<template>
  <div class="login">
    <TopNav tn-name="注册" title="用户登录"></TopNav>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">
          登录
        </van-button>
      </div>
    </van-form>
    <div class="v-btn">
      <van-button round size="small" type="danger" @click='toAnswer'>
        忘记密码
      </van-button>
    </div>
  </div>
</template>

<script>
  import TopNav from '@/components/TopNav.vue';

  export default{
    name: 'Login',
    components:{
      TopNav
    },
     data() {
        return {
          username: '',
          password: '',
        };
      },
      methods: {
        onSubmit() {
         var params = new URLSearchParams();
         params.append('username', this.username);
         params.append('password', this.password);

         this.axios.post('/rlg/user/login',params)
           .then((response) => {
             // 把用户信息保存起来
             if(response.data.code == 200){
               this.$store.commit('a',response.data.data);
               this.$router.push("/own");
             }else{
               this.$toast.fail(response.data.msg);
             }

           });
      },
      toAnswer(){
        this.$router.push("/fpwa")
      }
  },
  }
</script>

<style>
  .v-btn{
    height: 35px;
    width: 70px;
    margin: auto;
  }
</style>
